import dateScope from "./dateScope";
import moment from "moment";
var utils = {
  showLoading: true,
  gqIsTestTure: true,
  gqIsTestFalse: false,
  showPwdPage: true, // 是否输入账户密码进入页面
  planColor: "#fec05f",
  planColor1: "#ff7d4f",
  actualColor: "#41f1c9",
  actualColor1: "#3374ee",
  sumColor: "#c06c84", // 统计量
  xyText: 15, //  图表xy字体大小
  chartH: "70", // 字板块图表宽度
  qChartH: "40", // 全员营销板块图表宽度
  beginTime: "2017-8-1", // 全员营销开始时间
  lineW: 4, // 图标目标线宽度
  xData: ["月累计", "周目标", "周实际"],
  managerWeekTitle: ["指标名称", "当周计划", "当周实际完成", "下周计划"],
  managerMonthTitle: ["指标名称", "本月计划", "本月实际完成", "本月第一周计划"],
  managerWeekNextTitle: ["指标名称", "当周计划", "当周实际完成", "下月计划"],
  weekOptions: [{
    value: "",
    label: "本月"
  },
  {
    value: "1",
    label: "第1周"
  },
  {
    value: "2",
    label: "第2周"
  },
  {
    value: "3",
    label: "第3周"
  },
  {
    value: "4",
    label: "第4周"
  }
  ],
  reg: /^[0-9]+.?[0-9]*$/, // 是否为数字
  // 板块经营指标配置
  tableChart: {
    dc: {
      name: "地产",
      plateId: "2",
      indexIdsStr: "2001,2003,2005",
      imgName: "dclogo"
    },
    flh: {
      name: "房联行",
      plateId: "22",
      indexIdsStr: "2201",
      imgName: "flhlogo"
    },
    mwkj: {
      name: "浩德钢圈",
      plateId: "3",
      indexIdsStr: "3001,3003",
      imgName: "wllogo"
    },
    cfzx: {
      name: "财富中心",
      plateId: "41",
      indexIdsStr: "4103,4107,4109",
      imgName: "cflogo"
    },
    cyy: {
      name: "电商产业园",
      plateId: "5",
      indexIdsStr: "5001,5003,5005,5007,5009",
      imgName: "yclogo"
    }
  },
  analysisTableChart: {
    PartnerData: {
      name: "全员营销数据分析",
      plateId: "22",
      indexIdsStr: "2201"
    }
  },
  // 全员营销图标颜色
  chartsColor: [
    // 黑色主题
    {
      text: "#fff",
      line: "#2f3543",
      themeName: "black",
      serieColor: {
        planColor: ["#fec05f", "#ff7d4f"],
        actualColor: ["#41f1c9", "#3374ee"],
        lineColor: ["rgba(214,  84, 251,0.4 )", "rgba(214,  84, 251,0.1)"],
        targetColor: "#41f1c9"
      }
    },
    //  白色色主题
    {
      text: "black",
      line: "#2f3543",
      themeName: "white",
      serieColor: {
        planColor: ["#fec05f", "#ff7d4f"],
        actualColor: ["#41f1c9", "#3374ee"],
        lineColor: ["rgba(214,  84, 251,0.4 )", "rgba(214,  84, 251,0.1)"],
        targetColor: "#41f1c9"
      }
    }
  ],
  // 日期字符串 - / 格式化
  formatterDateStr(res) {
    if (String(res).indexOf("/")) {
      return res.replace(/\//g, ".");
    } else if (String(res).indexOf("-")) {
      return res.replace(/-/g, ".");
    }
  },
  formatterMonthFun(res) {
    // res.split(".").join("/")
    // console.log(res.replace(/\s/g, 'T').replace(/\//g, '-'))
    // console.log(moment(res.replace(/\s/g, 'T').replace(/\//g, '-')).isValid())
    // debugger
    var a = moment(res.replace(/\s/g, "T").replace(/\//g, "-")).format("M");
    return a + "月";
  },
  formatterAxisLabel(value) {
    if (value >= 1000 || value <= -1000) {
      value = value / 1000 + "千  ";
    } else {
      value = value + "  ";
    }
    // if ((value >= 10000 && value < 10000000) || (value <= -10000 && value > -10000000)) {
    //   value = value / 10000 + "万";
    // } else if (value >= 10000000 || value <= -10000000) {
    //   value = value / 10000000 + "千万";
    // }
    return value;
  },
  // 返回十一个月前时间
  formatterStartTime() {
    var date = new Date();
    debugger
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    if (month - 11 > 0) {
      month = month - 11;
    } else if (month === 1) {
      year = year - 1;
      month = month + 1;
    } else {
      year = year - 1;
      month = month - 1;
    }
    if (month < 10) {
      month = "0" + month;
    }
    var str = year + "-" + month + "-01";
    return str;
  },
  newFormatterLine(res, params, unit, titleUnit) {
    var dataObj = {};
    res.forEach(element => {
      if (element.name === params[0].axisValue) {
        dataObj = element;
      }
    });
    var minResult = "";
    var minItem =
      "<div style=\"display:flex;align-items:center;justify-content:space-between;padding:0 10px;line-height:1;\">" +
      "<div style=\"display:flex;align-items:center;margin-right:10px;\">" +
      "<span style=\"margin-right:10px;font-size:14px;\">" + dataObj.list[0].name + "</span>" +
      "<span style=\"margin-top:2px;font-family:DIN Condensed Bold;font-size:20px\">" + dataObj.list[0].value + "</span>" +
      "</div>" +
      "<div style=\"display:flex;align-items:center;margin-left:10px;\">" +
      "<span style=\"margin-right:10px;font-size:14px;\">" + dataObj.list[1].name + "</span>" +
      "<span style=\"margin-top:2px;font-family:DIN Condensed Bold;font-size:20px\">" + dataObj.list[1].value + "</span>" +
      "</div>" +
      "</div>" +
      "<em style=\"width:calc(100% - 24px);height:1px;margin-top:14px;margin-bottom:20px;background-color:rgba(0, 209, 255, 0.2);\"></em>" +
      "<div style=\"margin-bottom:15px;color:#ff7145;font-size:16px;line-height:1;\">截止当前累计</div>" +
      "<div style=\"display:flex;align-items:center;justify-content:space-between;padding:0 10px;line-height:1;\">" +
      "<div style=\"display:flex;align-items:center;margin-right:10px;\">" +
      "<span style=\"margin-right:10px;color:#ff7145;font-size:14px;\">" + dataObj.list[2].name + "</span>" +
      "<span style=\"margin-top:2px;color:#ff7145;font-family:DIN Condensed Bold;font-size:20px\">" + dataObj.list[2].value + "</span>" +
      "</div>" +
      "<div style=\"display:flex;align-items:center;margin-left:10px;\">" +
      "<span style=\"margin-right:10px;color:#ff7145;font-size:14px;\">" + dataObj.list[3].name + "</span>" +
      "<span style=\"margin-top:2px;color:#ff7145;font-family:DIN Condensed Bold;font-size:20px\">" + dataObj.list[3].value + "</span>" +
      "</div>" +
      "</div>";
    minResult += minItem;
    // params.forEach((item, id) => {
    //   var unitText = "";
    //   if (unit && typeof unit === "string") {
    //     unitText = unit;
    //   } else if (unit) {
    //     unitText = unit[id];
    //   }
    // });
    let color = "";
    if (params[0].color.color && params[0].color.color.colorStops) {
      color = params[0].color.color.colorStops[0].color;
    } else if (params[0].color && params[0].color.colorStops) {
      color = params[0].color.colorStops[0].color;
    } else {
      color = params[0].color;
    }
    if (params.length > 1) {
      color = "#f0bd26";
    }
    var tUnit = titleUnit || "";
    var imgConStart =
      "<div style=\"display:flex;padding:12px;color:" +
      color +
      ";flex-direction:column;align-items:center;position:relative;z-index:1;background:rgba(0,0,0,0.7);border:1px solid rgba(0,209,255,0.4);\">" +
      "<div style=\"margin-bottom:15px;color:#f0bd26;font-size:16px;line-height:1;\">" +
      params[0].name +
      tUnit +
      "</div>" +
      "<span style=\"position:absolute;top:-1px;left:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-right:none;border-bottom:none;\"></span>" +
      "<span style=\"position:absolute;top:-1px;right:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-left:none;border-bottom:none;\"></span>" +
      "<span style=\"position:absolute;bottom:-1px;left:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-top:none;border-right:none;\"></span>" +
      "<span style=\"position:absolute;right:-1px;bottom:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-top:none;border-left:none;\"></span>" +
      "<div style=\"width:100%;display:flex;align-items:center;justify-content:center;flex-direction:column;\">";
    var result =
      minResult === ""
        ? imgConStart + "</div>"
        : imgConStart + minResult + "</div>";
    return result;
  },
  formatterLine(res, params, unit, titleUnit) {
    var minResult = "";
    params.forEach((item, id) => {
      var unitText = "";
      if (unit && typeof unit === "string") {
        unitText = unit;
      } else if (unit) {
        unitText = unit[id];
      }
      var minItem =
        "<div style=\"display:flex;flex-direction:column;align-items:center;justify-content:space-between;padding:0 10px\"><div>" +
        item.seriesName +
        "</div><div style=\"margin-top:2px;font-family:DIN Condensed Bold;font-size:20px\">" +
        item.value +
        unitText +
        "</div></div>";
      minResult += minItem;
    });
    let color = "";
    if (params[0].color.color && params[0].color.color.colorStops) {
      color = params[0].color.color.colorStops[0].color;
    } else if (params[0].color && params[0].color.colorStops) {
      color = params[0].color.colorStops[0].color;
    } else {
      color = params[0].color;
    }
    if (params.length > 1) {
      color = "#f0bd26";
    }
    var tUnit = titleUnit || "";
    var imgConStart =
      "<div style=\"display:flex;padding:12px;color:" +
      color +
      ";flex-direction:column;align-items:center;position:relative;z-index:1;background:rgba(0,0,0,0.7);border:1px solid rgba(0,209,255,0.4);\">" +
      "<div style=\"margin-top:3px;color:#f0bd26;\">" +
      params[0].name +
      tUnit +
      "</div>" +
      "<span style=\"position:absolute;top:-1px;left:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-right:none;border-bottom:none;\"></span>" +
      "<span style=\"position:absolute;top:-1px;right:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-left:none;border-bottom:none;\"></span>" +
      "<span style=\"position:absolute;bottom:-1px;left:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-top:none;border-right:none;\"></span>" +
      "<span style=\"position:absolute;right:-1px;bottom:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-top:none;border-left:none;\"></span>" +
      "<div style=\"width:100%;display:flex;align-items:center;justify-content:center;flex-direction:row;margin-top:5px;color:#f0bd26;\">";

    var result =
      minResult === ""
        ? imgConStart + "</div>"
        : imgConStart + minResult + "</div>";
    return result;
  },
  threeDataFormatterLine(res, params, unit, titleUnit) {
    var dataObj = {};
    res.forEach(element => {
      if (element.name === params[0].axisValue) {
        dataObj = element;
      }
    });
    var minResult = "";
    var minItem =
      "<div style=\"display:flex;align-items:center;justify-content:space-between;padding:0 10px;line-height:1;\">" +
        "<div style=\"display:flex;align-items:center;margin-right:10px;\">" +
          "<span style=\"margin-right:10px;font-size:14px;\">" + dataObj.list[0].name + "</span>" +
          "<span style=\"margin-top:2px;font-family:DIN Condensed Bold;font-size:20px\">" + dataObj.list[0].value + "</span>" +
        "</div>" +
        "<div style=\"display:flex;align-items:center;margin-left:10px;\">" +
          "<span style=\"margin-right:10px;font-size:14px;\">" + dataObj.list[1].name + "</span>" +
          "<span style=\"margin-top:2px;font-family:DIN Condensed Bold;font-size:20px\">" + dataObj.list[1].value + "</span>" +
        "</div>" +
        "<div style=\"display:flex;align-items:center;margin-left:20px;\">" +
          "<span style=\"margin-right:10px;font-size:14px;\">" + dataObj.list[2].name + "</span>" +
          "<span style=\"margin-top:2px;font-family:DIN Condensed Bold;font-size:20px\">" + dataObj.list[2].value + "%</span>" +
        "</div>" +
      "</div>"
    minResult += minItem;
    // params.forEach((item, id) => {
    //   var unitText = "";
    //   if (unit && typeof unit === "string") {
    //     unitText = unit;
    //   } else if (unit) {
    //     unitText = unit[id];
    //   }
    // });
    let color = "";
    if (params[0].color.color && params[0].color.color.colorStops) {
      color = params[0].color.color.colorStops[0].color;
    } else if (params[0].color && params[0].color.colorStops) {
      color = params[0].color.colorStops[0].color;
    } else {
      color = params[0].color;
    }
    if (params.length > 1) {
      color = "#f0bd26";
    }
    var tUnit = titleUnit || "";
    var imgConStart =
      "<div style=\"display:flex;padding:12px;color:" +
      color +
      ";flex-direction:column;align-items:center;position:relative;z-index:1;background:rgba(0,0,0,0.7);border:1px solid rgba(0,209,255,0.4);\">" +
      "<div style=\"margin-bottom:15px;color:#f0bd26;font-size:16px;line-height:1;\">" +
      params[0].name +
      tUnit +
      "</div>" +
      "<span style=\"position:absolute;top:-1px;left:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-right:none;border-bottom:none;\"></span>" +
      "<span style=\"position:absolute;top:-1px;right:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-left:none;border-bottom:none;\"></span>" +
      "<span style=\"position:absolute;bottom:-1px;left:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-top:none;border-right:none;\"></span>" +
      "<span style=\"position:absolute;right:-1px;bottom:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-top:none;border-left:none;\"></span>" +
      "<div style=\"width:100%;display:flex;align-items:center;justify-content:center;flex-direction:column;\">";
    var result =
      minResult === ""
        ? imgConStart + "</div>"
        : imgConStart + minResult + "</div>";
    return result;
  },
  formatterModal(res, params, unit, color) {
    var minResult = "";
    if (res[0].list) {
      res[params[0].dataIndex].list.forEach(item => {
        var minItem =
          "<div style=\"display:flex;flex-direction:column;align-items:center;justify-content:space-between;padding:0 10px\"><span>" +
          item.name +
          "</span><span style=\"margin-top:2px;font-size:20px;font-family:DIN Condensed Bold\">" +
          item.value +
          "</span></div>";
        minResult += minItem;
      });
    }
    var index = params[0].dataIndex;
    var val = res[index].value;
    var nowColor = color || "#31cee6";
    var imgConStart =
      "<div style=\"display:flex;padding:12px 10px;color:" +
      nowColor +
      ";flex-direction:column;background:rgba(0,0,0,0.7);border-radius:10px;\">" +
      "<span style=\"width:100%;font-size:30px;padding:8pt 0 0 0 ;font-family:DIN Condensed Bold\">" +
      val +
      "</span>" +
      "<div style=\"width:100%;display:flex;align-items:center;justify-content:space-between;flex-direction:row;margin-top:8px;font-size:12px\">";

    var result =
      minResult === ""
        ? imgConStart + "</div>"
        : imgConStart + minResult + "</div>";
    return result;
  },
  // 饼图tooltip
  formatterPieTwo(res, params, unit) {
    var minResult = "";
    if (res[0].list) {
      res[params.dataIndex].list.forEach((item, id) => {
        var minItem =
          "<div style=\"display:flex;flex-direction:column;align-items:center;justify-content:space-between;padding:0 10px\"><span>" +
          item.name +
          "</span><span style=\"margin-top:2px;font-size:20px;font-family:DIN Condensed Bold\">" +
          item.value +
          "</span></div>";
        minResult += minItem;
      });
    }
    var val = params.data.value;
    var imgConStart =
      "<div style=\"display:flex;align-items:center;position:relative;z-index:1;padding:15px 20px;color:" +
      params.color +
      ";flex-direction:column;background:rgba(0,0,0,0.7);border:1px solid rgba(0,209,255,0.4);\">" +
      "<span style=\"width:100%;margin-top:3px;font-size:30px;font-family:DIN Condensed Bold\">" +
      val +
      "</span>" +
      "<span style=\"position:absolute;top:-1px;left:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-right:none;border-bottom:none;\"></span>" +
      "<span style=\"position:absolute;top:-1px;right:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-left:none;border-bottom:none;\"></span>" +
      "<span style=\"position:absolute;bottom:-1px;left:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-top:none;border-right:none;\"></span>" +
      "<span style=\"position:absolute;right:-1px;bottom:-1px;z-index:1;width:10px;height:10px;border:2px solid #48e5ff;border-top:none;border-left:none;\"></span>" +
      "<div style=\"width:100%;display:none;align-items:center;justify-content:space-between;flex-direction:row;margin-top:8pt;font-size:12px\">";

    var result =
      minResult === ""
        ? imgConStart + "</div>"
        : imgConStart + minResult + "</div>";
    return result;
  },
  // 获得某月的天数
  getMonthDays(myMonth) {
    var now = new Date(); // 当前日期
    var nowYear = now.getYear(); // 当前年
    var monthStartDate = new Date(nowYear, myMonth, 1);
    var monthEndDate = new Date(nowYear, myMonth + 1, 1);
    var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
    return days;
  },
  // 两个日期中的天数
  getTimeScope(res) {
    var days = res[1].getTime() - res[0].getTime();
    return parseInt(days / 1000 / 60 / 60 / 24);
  },
  // 获取当前日期getDateStr(0)、前几天getDateStr(-10)、后几天getDateStr(20)
  getDateStr(
    AddDayCount,
    inDate //  inDate格式为标准时间戳格式
  ) {
    var date = inDate || new Date();
    // 获取AddDayCount天后的日期
    date.setDate(date.getDate() + AddDayCount);
    var year = date.getFullYear();
    // day获取当前几号，不足10补0
    var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
    // month获取当前月份的日期，不足10补0
    var month =
      date.getMonth() + 1 > 9
        ? date.getMonth() + 1
        : "0" + (date.getMonth() + 1);
    return year + "-" + month + "-" + day;
  },
  formateDate(date) {
    var t = Date.parse(date);
    if (!isNaN(t)) {
      return new Date(Date.parse(date.replace(/-/g, "/")));
    } else {
      return new Date();
    }
  },
  // 格式化时间
  parseTime(time, cFormat) {
    if (arguments.length === 0) {
      return null;
    }
    const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
    let date;
    if (typeof time === "object") {
      date = time;
    } else {
      if (("" + time).length === 10) time = parseInt(time) * 1000;
      date = new Date(time);
    }
    const formatObj = {
      y: date.getFullYear(),
      m: date.getMonth() + 1,
      d: date.getDate(),
      h: date.getHours(),
      i: date.getMinutes(),
      s: date.getSeconds(),
      a: date.getDay()
    };
    const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
      let value = formatObj[key];
      if (key === "a") {
        return ["一", "二", "三", "四", "五", "六", "日"][value - 1];
      }
      if (result.length > 0 && value < 10) {
        value = "0" + value;
      }
      return value || 0;
    });
    return time_str;
  },
  // 获取图标的文字样式
  getChartColor(self) {
    var data = JSON.parse(self.$localStorage.get("themeData"));
    return data ? data.chartsColor : this.chartsColor[0];
  },
  getWeek(month, date, value) {
    var week = {};
    week.num = 1;
    if (value) {
      var range = dateScope[month][value - 1];
      week.range = month + "." + range.start + "-" + month + "." + range.end;
    } else {
      dateScope[month].forEach((item, index) => {
        if (item.start <= date && item.end >= date) {
          week.num = index + 1;
          week.range = month + "." + item.start + "-" + month + "." + item.end;
        }
      });
    }
    return week;
  },
  // 根据单位判断取小数点后几位
  numForUnit(num, unit) {
    unit = String(unit);
    num = String(num);
    if (unit.indexOf("万") >= 0 || unit.indexOf("吨") >= 0) {
      return Number(num).toFixed(2);
    } else {
      if (num.indexOf(".") >= 0) {
        num = num.slice(0, num.indexOf("."));
      }
      return num;
    }
  },
  getUserInfo(name) {
    var blockNames = [
      "zhdMWKJ",
      "zhdDC",
      "zhdFlh",
      "zhdJK",
      "zhdCYY",
      "zhdRM",
      "zhdXZ",
      "admin",
      "zhdXRXBB",
      "zhdSJFWB",
      "zhdCWB"
    ];
    var data = {};
    switch (name) {
      case "zhddc":
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "浩德鑫置地",
          name: "zhdDC",
          role: ["zhdDC"],
          token: "zhdDC"
        };
        break;
      case blockNames[0]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "浩德钢圈",
          name: blockNames[0],
          role: [blockNames[0]],
          token: blockNames[0]
        };
        break;
      case blockNames[1]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "浩德鑫置地",
          name: blockNames[1],
          role: [blockNames[1]],
          token: blockNames[1]
        };
        break;
      case blockNames[2]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "房联行",
          name: blockNames[2],
          role: [blockNames[2]],
          token: blockNames[2]
        };
        break;
      case blockNames[3]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "浩德金控",
          name: blockNames[3],
          role: [blockNames[3]],
          token: blockNames[3]
        };
        break;
      case blockNames[4]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "产业园",
          name: blockNames[4],
          role: [blockNames[4]],
          token: blockNames[4]
        };
        break;
      case blockNames[5]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "浩德融媒",
          name: blockNames[5],
          role: [blockNames[5]],
          token: blockNames[5]
        };
        break;
      case blockNames[6]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "集团行政",
          name: blockNames[6],
          role: [blockNames[6]],
          token: blockNames[6]
        };
        break;
      case blockNames[7]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "超级管理员",
          name: blockNames[7],
          role: [blockNames[7]],
          token: blockNames[7]
        };
        break;
      case blockNames[8]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "行政人力信息保卫",
          name: blockNames[8],
          role: [blockNames[8]],
          token: blockNames[8]
        };
        break;
      case blockNames[9]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "审计法务",
          name: blockNames[9],
          role: [blockNames[9]],
          token: blockNames[9]
        };
        break;
      case blockNames[10]:
        data = {
          avatar: "https:// wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
          introduction: "财务",
          name: blockNames[10],
          role: [blockNames[10]],
          token: blockNames[10]
        };
        break;

      default:
        data = {};
    }
    return data;
  },
  // 多tabs图表  TabChartsArr
  returnTabChartsArr(initData) {
    var tabChartsArr = [];
    initData.forEach((itemData, index) => {
      var series = [];
      itemData.yData.forEach((item, id) => {
        // 返回seriesItem
        var itemY = {};
        itemY.type = item.type;
        itemY.name = itemData.legend[id];
        itemY.data = item.data;
        itemY.yAxisIndex = Number(id) >= 1 ? 1 : 0;
        if (itemData.stack) {
          itemY.stack = itemData.stack;
        }
        if (item.type === "line") {
          itemY.symbol = "circle";
          itemY.smooth = true; // 线条圆润
          itemY.symbolSize = 10;
          //  itemData.lineStyle = {
          //      normal: {
          //          width: 3,
          //          color: '#f86f39'
          //      }
          //  }
          if (itemData.linearColor) {
            var startColor = itemData.linearColor[id].startColor;
            var endColor = itemData.linearColor[id].endColor;
            itemY.itemStyle = {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [{
                    offset: 0,
                    color: startColor //  0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: endColor //  100% 处的颜色
                  }
                  ],
                  globalCoord: false //  缺省为 false
                }
              }
            };
            itemY.areaStyle = {
              normal: {}
            };
          }
        }
        if (item.type === "bar") {
          itemData.barWidth = item.barWidth ? item.barWidth : 40;
          if (itemData.linearColor) {
            startColor = itemData.linearColor[id].startColor;
            endColor = itemData.linearColor[id].endColor;
            if (initData.exchange) {
              itemY.itemStyle = {
                normal: {
                  color: {
                    type: "linear",
                    x: 0,
                    y: 0,
                    x2: 1,
                    y2: 1,
                    colorStops: [{
                      offset: 0,
                      color: startColor //  0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: endColor //  100% 处的颜色
                    }
                    ],
                    globalCoord: false //  缺省为 false
                  }
                }
              };
            } else {
              itemY.itemStyle = {
                normal: {
                  color: {
                    type: "linear",
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                      offset: 0,
                      color: startColor //  0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: endColor //  100% 处的颜色
                    }
                    ],
                    globalCoord: false //  缺省为 false
                  }
                }
              };
            }
          }
        }
        series.push(itemY);
      });
      itemData.series = series;
      tabChartsArr.push(itemData);
    });
    return tabChartsArr;
  },
  returnTabsChartOption(itemData, id) {
    var textColor = itemData.textColor ? itemData.textColor : [];
    var option = {
      color: itemData.color ? itemData.color : ["white"],
      legend: {
        show: itemData.legendShow !== undefined ? itemData.legendShow : true,
        data: itemData.legend ? itemData.legend : [],
        bottom: 10,
        textStyle: {
          color: textColor
        }
      },
      tooltip: {
        trigger: "axis",
        show: !itemData.xyshow,
        textStyle: {
          color: textColor
        },
        axisPointer: {
          lineStyle: {
            color: "#f86f39",
            type: "dashed",
            width: 2
          }
        },
        formatter: function(params) {
          var result = "";
          for (let i = 0; i < params.length; i++) {
            const item = params[i];
            if (item.seriesName.indexOf("(") >= 0) {
              result +=
                "<span style=\"display:inline-block;margin-bottom: 4px;margin-right:5px;width:9px;height:3px;background-color:" +
                item.color +
                "\"></span>" +
                item.axisValue +
                "</br>" +
                item.seriesName.slice(0, item.seriesName.indexOf("(")) +
                "&nbsp; : &nbsp; " +
                item.data +
                unit +
                "</br>";
            } else {
              var color = item.color.colorStops
                ? item.color.colorStops[0].color
                : item.color;
              result +=
                "<span style=\"display:inline-block;margin-bottom: 4px;margin-right:5px;width:9px;height:3px;background-color:#f86f39" +
                "\">" +
                "</span>" +
                item.axisValue +
                "</br>" +
                item.seriesName +
                "&nbsp; : &nbsp; " +
                "<span style=\"font-size:1.5em\">" +
                item.data +
                "</span></br>";
            }
          }
          return result;
        }
      },
      xAxis: [{
        data: itemData.xData,
        boundaryGap: itemData.series[0].type === "bar" && true,
        show: !itemData.xyshow,
        nameTextStyle: {
          color: textColor
        },
        axisLine: {
          lineStyle: {
            color: textColor
          }
        },
        axisLabel: {
          textStyle: {
            color: textColor
          }
        },
        splitLine: {
          lineStyle: {
            color: textColor
          }
        }
      }],
      yAxis: [{
        name: itemData.yAxisName ? itemData.yAxisName : "",
        type: "value",
        show: !itemData.xyshow,
        nameTextStyle: {
          color: textColor
        },
        axisLabel: {
          textStyle: {
            color: textColor
          }
        },
        axisLine: {
          lineStyle: {
            color: textColor
          }
        },
        splitLine: {
          show: false,
          lineStyle: {
            color: textColor
          }
        }
      }],
      grid: [{
        left: "10%",
        right: "3%",
        top: "10%"
      }],
      series: itemData.series
    };
    if (itemData.color && itemData.color.length > 0) {
      option.color = itemData.color;
    }
    if (itemData.xAxisLine) {
      option.xAxis.forEach(item => {
        itemData.xAxisLine.axisLabel
          ? (item.axisLabel = itemData.xAxisLine.axisLabel)
          : "";
        itemData.xAxisLine.axisLine
          ? (item.axisLine = itemData.xAxisLine.axisLine)
          : "";
        itemData.xAxisLine.splitLine
          ? (item.splitLine = itemData.xAxisLine.splitLine)
          : "";
      });
    }
    if (itemData.yAxisLine) {
      option.yAxis.forEach(item => {
        itemData.yAxisLine.axisLabel
          ? (item.axisLabel = itemData.yAxisLine.axisLabel)
          : "";
        itemData.yAxisLine.axisLine
          ? (item.axisLine = itemData.yAxisLine.axisLine)
          : "";
        itemData.yAxisLine.splitLine
          ? (item.splitLine = itemData.yAxisLine.splitLine)
          : "";
      });
    }
    if (itemData.yAxis) {
      option.yAxis.push(itemData.yAxis);
    }
    itemData.option = option;
    return itemData;
  },
  // 单图表 return  options
  returnItemSeries(initData) {
    var textColor = initData.textColor ? initData.textColor : "black";
    var series = [];
    var seriesItemType = "";
    var pieSeriesData = [];
    var pieName = initData.pieName ? initData.pieName : "";
    var showYAxisRight = initData.yAxis && true;
    //  var max = 0
    initData.yData.forEach((item, id) => {
      // pie类型
      if (item.type === undefined) {
        item.forEach(aa => {
          var itemData = {};
          seriesItemType = aa.type;
          itemData.value = aa.value;
          itemData.name = aa.name;
          itemData.selected = aa.selected ? aa.selected : false;
          pieSeriesData.push(itemData);
        });
      } else {
        var itemData = {};
        itemData.type = item.type;
        itemData.name = initData.legendObj
          ? initData.legendObj.data[id].name
          : initData.legend[id];
        itemData.data = item.data;
        if (showYAxisRight) {
          itemData.yAxisIndex = Number(id) >= 1 ? 1 : 0;
        }
        if (initData.stack) {
          itemData.stack = initData.stack;
        }
        if (initData.itemColorArr) {
          itemData.data.forEach((bb, bId) => {
            var cc = {};
            cc.value = bb;
            cc.itemStyle = {
              normal: {
                color: initData.itemColorArr[bId]
              }
            };
          });
          //  itemData.itemStyle={
          //      normal:{
          //          color:initData.itemColorArr[id]
          //      }
          //  }
        }

        if (item.type === "line") {
          itemData.smooth = true; // 线条圆润
          itemData.symbolSize = 10;
          itemData.symbol = item.symbol ? item.symbol : "circle";
          //  itemData.lineStyle = {
          //      normal: {
          //          width: 3,
          //          color: '#f86f39'
          //      }
          //  }
          if (initData.linearColor) {
            var startColor = initData.linearColor[id].startColor;
            var endColor = initData.linearColor[id].endColor;
            var colorS = startColor.split(",");
            var relColor = "";
            colorS.forEach((item, id) => {
              if (id > 2) return;
              relColor += item + ",";
            });
            relColor = relColor + "1)";
            itemData.itemStyle = {
              normal: {
                color: relColor
              }
            };
            itemData.areaStyle = {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [{
                    offset: 0,
                    color: startColor //  0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: endColor //  100% 处的颜色
                  }
                  ],
                  globalCoord: false //  缺省为 false
                },
                shadowColor: "rgba(0, 0, 0, 0.1)",
                shadowBlur: 10
              }
            };
          }
        }
        if (item.type === "bar") {
          itemData.barWidth = item.barWidth ? item.barWidth : 40;
          if (initData.linearColor) {
            startColor = initData.linearColor[id].startColor;
            endColor = initData.linearColor[id].endColor;
            if (initData.color && initData.color.length > 0) {} else {
              if (initData.exchange) {
                itemData.itemStyle = {
                  normal: {
                    color: {
                      type: "linear",
                      x: 0,
                      y: 0,
                      x2: 1,
                      y2: 0,
                      colorStops: [{
                        offset: 0,
                        color: endColor //  0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: startColor //  100% 处的颜色
                      }
                      ],
                      globalCoord: false //  缺省为 false
                    }
                  }
                };
              } else {
                itemData.itemStyle = {
                  normal: {
                    color: {
                      type: "linear",
                      x: 0,
                      y: 0,
                      x2: 0,
                      y2: 1,
                      colorStops: [{
                        offset: 0,
                        color: endColor //  0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: startColor //  100% 处的颜色
                      }
                      ],
                      globalCoord: false //  缺省为 false
                    }
                  }
                };
              }
              itemData.areaStyle = {
                normal: {}
              };
            }
          } else if (initData.yData && initData.yData.length === 1) {
            //  max = 40
            itemData.itemStyle = {
              normal: {
                color: function(params) {
                  var num = initData.color.length;
                  return initData.color[params.dataIndex % num];
                }
              }
            };
          } else {
            //  max = null
          }

          itemData.label = initData.itemLabel
            ? initData.itemLabel : {
              normal: {
                show: true,
                position: "inside"
              }
            };
        }
        if (item.type === "pictorialBar") {
          series = item;
        } else {
          series.push(itemData);
        }
      }
    });
    if (seriesItemType === "pie") {
      series = [{
        name: pieName,
        type: "pie",
        radius: initData.radius ? initData.radius : "55%",
        center: initData.center ? initData.center : ["50%", "60%"],

        label: initData.label
          ? initData.label : {
            normal: {
              position: "inner"
            }
          },
        labelLine: initData.labelLine ? initData.labelLine : {},
        itemStyle: initData.itemStyle ? initData.itemStyle : null,
        data: pieSeriesData
      }];
      initData.series = series;
      var unit = initData.unit ? initData.unit : "";
      var option = {
        title: initData.title ? initData.title : {},
        tooltip: initData.tooltip
          ? initData.tooltip : {
            trigger: "item",
            extraCssText: "text-align:center;background-color:transparent",
            formatter: function(params) {
              var result = "";
              var topResult = "";
              var bottomResult = "";
              var bottomResultCon = "";
              topTitle = params.name;
              //  result += '<span style="display:inline-block;margin-bottom: 4px;margin-right:5px;width:9px;height:3px;background-color:' + color  + '">' + '</span>' + item.axisValue + seriesName  + '<span style="font-size:1.5em">'+ item.data + '</span>'+ unit+'</br>'
              bottomResult +=
                "<p style=\"margin:5px 50%;width:100%;text-align:left\"><span style=\"text-align:left\">" +
                params.value +
                "</span><span style=\"margin:0 5px\">" +
                unit +
                "(" +
                params.percent +
                "%)</span>" +
                "</p>";

              topResult =
                "<div style=\"display:flex;padding:10px;justify-content: center;align-items: cente;background:#2d8fc1;border-top-right-radius:5px;border-top-left-radius:5px\">" +
                params.name +
                "</div>";
              bottomResultCon =
                "<div style=\"display:flex;flex-direction: column;padding:0 10px;justify-content:space-around;align-items: center;background:#0e46b0;border-bottom-right-radius:5px;border-bottom-left-radius:5px\">" +
                bottomResult +
                "</div>";
              result = topResult + bottomResultCon;
              return result;
            }
            //  formatter: initData.toolTipFormatter ? initData.toolTipFormatter : "{b} : {c} "+unit+" ({d}%)",
          },
        legend: initData.legendObj
          ? initData.legendObj : {
            formatter: function() {
              return "";
            },
            show: initData.legendShow != undefined ? initData.legendShow : true,
            data: initData.legend
              ? initData.legend : [initData.yData[0][0].name],
            left: "center",
            top: "center",
            align: "center",
            textStyle: {
              color: "#fff",
              fontSize: 50
            }
          },
        series: series
      };
      if (initData.color && initData.color.length > 0) {
        option.color = initData.color;
      }
      if (initData.seriesCenter && initData.seriesCenter.length > 0) {
        option.series = option.series.concat(initData.seriesCenter);
      }
    } else {
      initData.series = series;
      // 组装options
      //  基于准备好的dom，初始化echarts实例
      option = {
        title: initData.title ? initData.title : "",
        legend: initData.legendObj
          ? initData.legendObj : {
            show: initData.legendShow != undefined ? initData.legendShow : true,
            data: initData.legend,
            bottom: 5,
            textStyle: {
              color: textColor
            }
          },
        tooltip: initData.tooltip
          ? initData.tooltip : {
            trigger: "axis",
            show: !initData.xyshow,
            textStyle: {
              color: textColor,
              "text-align": "center"
            },
            extraCssText: "text-align:center;background-color:transparent",
            axisPointer: {
              type: "shadow",
              lineStyle: {
                //  color:'#f86f39',
                type: "shadow",
                width: 2
              }
            },
            formatter: function(params) {
              var result = "";
              var topResult = "";
              var bottomResult = "";
              var bottomResultCon = "";
              var topTitle = "";
              var unit = initData.unit ? initData.unit : "";
              for (let i = 0; i < params.length; i++) {
                const item = params[i];
                if (item.seriesName.indexOf("(") >= 0) {
                  result +=
                    "<span style=\"display:inline-block;margin-bottom: 4px;margin-right:5px;width:9px;height:3px;background-color:" +
                    item.color +
                    "\"></span>" +
                    item.axisValue +
                    "</br>" +
                    item.seriesName.slice(0, item.seriesName.indexOf("(")) +
                    "&nbsp; : &nbsp; " +
                    item.data +
                    unit +
                    "</br>";
                } else {
                  var color = item.color.colorStops
                    ? item.color.colorStops[0].color
                    : item.color;
                  var seriesName =
                    item.seriesName.indexOf("-") >= 0
                      ? ""
                      : item.seriesName + "&nbsp:&nbsp";
                  topTitle = item.axisValue;
                  //  result += '<span style="display:inline-block;margin-bottom: 4px;margin-right:5px;width:9px;height:3px;background-color:' + color  + '">' + '</span>' + item.axisValue + seriesName  + '<span style="font-size:1.5em">'+ item.data + '</span>'+ unit+'</br>'
                  bottomResult +=
                    "<p style=\"margin:5px 50%;width:100%;text-align:left\"><span style=\"text-align:left\">" +
                    seriesName +
                    item.data +
                    "</span><span style=\"margin:0 5px\">" +
                    unit +
                    "</span>" +
                    "</p>";
                }
              }
              topResult =
                "<div style=\"display:flex;padding:10px;justify-content: center;align-items: cente;background:#2d8fc1;border-top-right-radius:5px;border-top-left-radius:5px\">" +
                topTitle +
                "</div>";
              bottomResultCon =
                "<div style=\"display:flex;flex-direction: column;padding:0 10px;justify-content:space-around;align-items: center;background:#0e46b0;border-bottom-right-radius:5px;border-bottom-left-radius:5px\">" +
                bottomResult +
                "</div>";
              result = topResult + bottomResultCon;
              return result;
            }
          },
        xAxis: [{
          name: initData.xAxisName ? initData.xAxisName : "",
          type: "category",
          data: initData.xData,
          nameRotate: initData.nameRotate ? initData.nameRotate : 0,
          //  boundaryGap: initData.series[0].type == "bar" ? true : false,
          //  show: initData.xAxisName ? initData.xAxisName : !initData.xyshow,
          nameTextStyle: {
            color: textColor
          },
          axisLine: {
            lineStyle: {
              color: textColor
            }
          },
          axisLabel: {
            textStyle: {
              color: textColor
            }
          },
          splitLine: {
            lineStyle: {
              color: textColor
            }
          }
        }],
        yAxis: [{
          type: "value",
          name: initData.yAxisName ? initData.yAxisName : "",
          show: !initData.xyshow,
          splitNumber: initData.splitNumber ? initData.splitNumber : null,
          max: initData.max ? initData.max : null,
          nameTextStyle: {
            color: textColor
          },
          axisLabel: {
            textStyle: {
              color: textColor
            }
          },
          axisLine: {
            lineStyle: {
              color: textColor
            }
          },
          splitLine: {
            show: false,
            lineStyle: {
              color: textColor
            }
          }
        }],
        grid: initData.grid
          ? initData.grid : [{
            left: "12%",
            right: "3%",
            top: "11%"
          }],
        series: initData.series
      };
      if (initData.exchange === undefined || !initData.exchange) {} else {
        option.xAxis = [{
          type: "value",
          name: initData.yAxisName ? initData.yAxisName : "",
          boundaryGap: initData.series[0].type === "bar" && true,
          show: !initData.xyshow,
          nameTextStyle: {
            color: textColor
          },
          axisLine: {
            lineStyle: {
              color: textColor
            }
          },
          axisLabel: {
            textStyle: {
              color: textColor
            }
          },
          splitLine: {
            lineStyle: {
              color: textColor
            }
          }
        }];
        option.yAxis = [{
          show: !initData.xyshow,
          type: "category",
          data: initData.xData,
          name: initData.xAxisName ? initData.xAxisName : "",
          nameTextStyle: {
            color: textColor
          },
          axisLabel: {
            textStyle: {
              color: textColor
            }
          },
          axisLine: {
            lineStyle: {
              color: textColor
            }
          },
          splitLine: {
            show: false,
            lineStyle: {
              color: textColor
            }
          }
        }];
      }
      if (initData.color && initData.color.length > 1) {
        option.color = initData.color;
      }
      if (initData.yAxis) {
        option.yAxis.push(initData.yAxis);
      }
      if (initData.xAxisLine) {
        option.xAxis.forEach(item => {
          initData.xAxisLine.axisLabel
            ? (item.axisLabel = initData.xAxisLine.axisLabel)
            : "";
          initData.xAxisLine.axisLine
            ? (item.axisLine = initData.xAxisLine.axisLine)
            : "";
          initData.xAxisLine.splitLine
            ? (item.splitLine = initData.xAxisLine.splitLine)
            : "";
          initData.xAxisLine.axisTick
            ? (item.axisTick = initData.xAxisLine.axisTick)
            : "";
        });
      }
      if (initData.yAxisLine) {
        option.yAxis.forEach(item => {
          initData.yAxisLine.axisLabel
            ? (item.axisLabel = initData.yAxisLine.axisLabel)
            : "";
          initData.yAxisLine.axisLine
            ? (item.axisLine = initData.yAxisLine.axisLine)
            : "";
          initData.yAxisLine.splitLine
            ? (item.splitLine = initData.yAxisLine.splitLine)
            : "";
          initData.yAxisLine.axisTick
            ? (item.axisTick = initData.yAxisLine.axisTick)
            : "";
        });
      }
    }
    var allOption = {};
    allOption.baseOption = option;
    allOption.media = [];
    if (initData.media) {
      allOption.media = initData.media;
    }
    return option;
  }
};

export default utils;
